home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / object / sel_obj.pro < prev    next >
Text File  |  1997-07-08  |  8KB  |  225 lines

  1. ; $Id: sel_obj.pro,v 1.2 1997/03/26 20:40:21 griz Exp $
  2. ;
  3. ; Copyright (c) 1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;    SEL_OBJ
  8. ;
  9. ; PURPOSE:
  10. ;    This procedure demonstrates how to perform selections of
  11. ;    views, models, and graphic atoms using object graphics.
  12. ;
  13. ;    This procedure creates a simple widget application that allows 
  14. ;       the user to click the mouse within views to make selections.  
  15. ;       The user may choose between model selections or graphic atom
  16. ;       selections.  The current selection(s) are identified for the user.
  17. ;
  18. ; CATEGORY:
  19. ;    Object graphics.
  20. ;
  21. ; CALLING SEQUENCE:
  22. ;    SEL_OBJ
  23. ;
  24. ; MODIFICATION HISTORY:
  25. ;     Written by:    DD, February 1997.
  26. ;-
  27.  
  28. ;----------------------------------------------------------------------------
  29. ; SEL_OBJ_EVENT
  30. ;
  31. ; Purpose:
  32. ;  Handle events for the selection example.
  33. ;
  34. PRO sel_obj_event, sEvent
  35.  
  36.     ; Handle kill requests.
  37.     IF (TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ 'WIDGET_KILL_REQUEST') THEN BEGIN
  38.         WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  39.         OBJ_DESTROY, sState.oScene
  40.         OBJ_DESTROY, sState.oImage
  41.         WIDGET_CONTROL, sEvent.top, /DESTROY
  42.         RETURN
  43.     ENDIF
  44.  
  45.     ; Handle other events.
  46.     WIDGET_CONTROL, sEvent.id, GET_UVALUE=uval
  47.     CASE uval OF
  48.         'DRAW': BEGIN
  49.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  50.  
  51.             CASE sEvent.type OF
  52.                 0: BEGIN ; Button Press.
  53.                       ; First, select the view.
  54.                       oViewArr = sState.oWindow->Select(sState.oScene, $
  55.                                 [sEvent.x, sEvent.y], DIMENSIONS=[20,20] )
  56.                       nSel = N_ELEMENTS(oViewArr)
  57.                       ; If we have a view selection...
  58.                       IF ((SIZE(oViewArr))[0] NE 0) THEN BEGIN
  59.                           oView = oViewArr[0] 
  60.  
  61.                           ; Now select an object within the view. 
  62.                           oObjArr = sState.oWindow->Select(oView, $
  63.                                     [sEvent.x, sEvent.y], DIMENSIONS=[20,20] )
  64.                           nSel = N_ELEMENTS(oObjArr)
  65.  
  66.                           ; If we have an object selection...
  67.                           IF ((SIZE(oObjArr))[0] NE 0) THEN BEGIN
  68.                               FOR i=0, nSel-1 DO BEGIN
  69.                                   oObjArr[i]->GetProperty, NAME=name
  70.                                   IF (i EQ 0) THEN $
  71.                                       label = 'Current Selections: ' + name $
  72.                                   ELSE $
  73.                                       label = label + ', ' + name 
  74.                               ENDFOR
  75.                           ENDIF ELSE BEGIN
  76.                               oView->GetProperty, NAME=name  
  77.                               label = 'Current Selections: ' + name
  78.                           ENDELSE
  79.                       ENDIF ELSE BEGIN
  80.                           label = 'Current Selections: <None>'
  81.                       ENDELSE
  82.                       WIDGET_CONTROL, sState.wLabel, SET_VALUE=label
  83.                   END
  84.                 4: BEGIN ; Exposure.
  85.                       sState.oWindow->Draw, sState.oScene
  86.                   END
  87.                 ELSE: BEGIN 
  88.                     ; Do Nothing.
  89.                   END
  90.             ENDCASE 
  91.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
  92.           END
  93.         'SELECT': BEGIN
  94.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
  95.             ; Set the model as a selection target as requested by user.
  96.             sState.oSurfModel->SetProperty, SELECT_TARGET=(1-sEvent.Value) 
  97.             sState.oPlotModel->SetProperty, SELECT_TARGET=(1-sEvent.Value)
  98.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY            
  99.           END
  100.     ENDCASE
  101. END
  102.  
  103. ;----------------------------------------------------------------------------
  104. ; SEL_OBJ
  105. ;
  106. ; Purpose:
  107. ;  This procedure creates a simple widget application that demonstrates
  108. ;  object selection.
  109. ;
  110. PRO sel_obj
  111.     xdim = 480
  112.     ydim = 360
  113.  
  114.     ; Create the widgets.
  115.     wBase = WIDGET_BASE(TITLE='Selection Example', /COLUMN, $
  116.                         /TLB_KILL_REQUEST_EVENTS )
  117.     wDraw = WIDGET_DRAW(wBase, XSIZE=xdim, YSIZE=ydim, GRAPHICS_LEVEL=2, $
  118.                         RETAIN=0, $
  119.                         /BUTTON_EVENTS, /EXPOSE_EVENTS, UVALUE='DRAW')
  120.     wSelGroup = CW_BGROUP(wBase, $
  121.                           ['Model', 'Graphic Atoms'], $
  122.                           LABEL_LEFT='Selection Target:', /EXCLUSIVE, /ROW, $
  123.                           /NO_RELEASE, SET_VALUE=1, UVALUE='SELECT')
  124.     wLabel = WIDGET_LABEL(wBase, VALUE='Current Selections: <None>', $
  125.                           /DYNAMIC_RESIZE)
  126.  
  127.     WIDGET_CONTROL, wBase, /REALIZE
  128.     WIDGET_CONTROL, wDraw, GET_VALUE=oWindow
  129.  
  130.     ; Create a scene.
  131.     oScene = OBJ_NEW('IDLgrScene')
  132.  
  133.     ; Create the views.
  134.     aspect = FLOAT(xdim/2) / FLOAT(ydim)
  135.     IF (aspect > 1.) THEN BEGIN
  136.         vrect = [-aspect, -1, aspect * 2.0, 2.0]
  137.     ENDIF ELSE BEGIN
  138.         vrect = [-1, -1 - (((1./aspect) - 1)/2.), 2, 2.0/aspect]
  139.     ENDELSE
  140.     oView1 = OBJ_NEW('IDLgrView', LOCATION=[0,0], DIMENSIONS=[xdim/2,ydim],$
  141.                      COLOR=[60,60,60], NAME='View 1' )
  142.     oScene->Add, oView1
  143.     oView2 = OBJ_NEW('IDLgrView', LOCATION=[xdim/2,0], $
  144.                      DIMENSIONS=[xdim/2,ydim], VIEWPLANE_RECT=vrect, $
  145.                      COLOR=[0,0,0], NAME='View 2')
  146.     oScene->Add, oView2
  147.  
  148.     ; Create a top-level plot model for the first view.
  149.     oPlotModel = OBJ_NEW('IDLgrModel', NAME='Cosine Plot Model')
  150.     oView1->Add, oPlotModel
  151.   
  152.     ; Create some plot data.
  153.     xData = FINDGEN(100) / 99.
  154.     yData = COS(xData*!PI)
  155.     xMax = MAX(xData, MIN=xMin)
  156.     yMax = MAX(yData, MIN=yMin)
  157.     xRange = xMax - xMin
  158.     yRange = yMax - yMin
  159.     xPad = xRange * 0.3
  160.     yPad = yRange * 0.2
  161.     oView1->SetProperty, VIEWPLANE_RECT = [xMin-xPad, yMin - yPad, $
  162.                                            xRange + 2*xPad, yRange + 2*yPad]
  163.     ; X axis.
  164.     xTickLen = 0.05 * yRange
  165.     oXAxis = OBJ_NEW('IDLgrAxis', 0, LOCATION=[xMin, yMin], $
  166.                      RANGE=[xMin, xMax], COLOR=[60,200,90], TICKLEN=xTicklen, $
  167.                      NAME='X Axis', MAJOR=3)
  168.     oPlotModel->Add, oXAxis
  169.  
  170.     ; Y axis.
  171.     yTickLen = 0.05 * xRange
  172.     oYAxis = OBJ_NEW('IDLgrAxis', 1, LOCATION=[xMin, yMin], $
  173.                      RANGE=[yMin, yMax], COLOR=[60,200,90], TICKLEN=yTicklen, $
  174.                      NAME='Y Axis')     
  175.     oPlotModel->Add, oYAxis
  176.  
  177.     ; Plot.
  178.     oPlot = OBJ_NEW('IDLgrPlot', xDAta, yData, COLOR=[60,200,90], $
  179.                      NAME='Plot Line')
  180.     oPlotModel->Add, oPlot
  181.  
  182.     ; Create a top-level surface model for the second view.
  183.     oSurfModel = OBJ_NEW('IDLgrModel', NAME='DIST Model')
  184.     oSurfModel->Rotate, [1,0,0], -90
  185.     oSurfModel->Rotate, [0,1,0], 30
  186.     oSurfModel->Rotate, [1,0,0], 30
  187.     oView2->Add, oSurfModel
  188.  
  189.     ; Create some surface data.
  190.     zData = BESELJ(SHIFT(DIST(20),10,10)/2,0) * 0.8
  191.     xData = (FINDGEN(20) - 10.) / 20.
  192.     yData = xData
  193.  
  194.     ; Surface.
  195.     oSurface = OBJ_NEW('IDLgrSurface', zData, xData, yData, COLOR=[255,90,60],$
  196.                        STYLE=1, NAME='Surface')
  197.     oSurfModel->Add, oSurface
  198.  
  199.     oImage = OBJ_NEW('IDLgrImage', BYTSCL(zData), /GREYSCALE)
  200.     xMax = MAX(xData, MIN=xMin)
  201.     yMax = MAX(yData, MIN=yMin)
  202.     zMax = MAX(zData, MIN=zMin)
  203.     zMin = zMin - 0.2
  204.     oPolygon = OBJ_NEW('IDLgrPolygon', [xMin, xMax, xMax, xMin], $
  205.                         [yMin, yMin, yMax, yMax], [zMin, zMin, zMin, zMin], $
  206.                         TEXTURE_MAP=oImage, $
  207.                         TEXTURE_COORD=[[0,0],[1,0],[1,1],[0,1]],$
  208.                         COLOR=[255,255,255], NAME='Image' )
  209.     oSurfModel->Add, oPolygon
  210.  
  211.     ; Draw.
  212.     oWindow->Draw, oScene
  213.  
  214.     ; Store the state in a structure.
  215.     sState = { wLabel : wLabel,        $
  216.                oWindow: oWindow,       $
  217.                oScene: oScene,         $
  218.                oImage: oImage,         $
  219.                oPlotModel: oPlotModel, $
  220.                oSurfModel: oSurfModel  $
  221.              }
  222.     WIDGET_CONTROL, wBase, SET_UVALUE=sState, /NO_COPY
  223.  
  224.     XMANAGER, 'sel_obj', wBase, /NO_BLOCK
  225. END